<template>
  <el-dialog v-model="editCodeDialog" title="修改入群码" width="350px">
    <el-form :model="form" label-width="80px">
      <el-form-item label="入群码">
        <el-input v-model="form.value"></el-input>
      </el-form-item>
      <el-form-item label="使用状态">
        <el-select v-model="form.status">
          <el-option label="未使用" :value="0"></el-option>
          <el-option label="已使用" :value="1"></el-option>
          <el-option label="已销毁" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="使用者QQ">
        <el-input v-model="form.qq"/>
      </el-form-item>
      <el-form-item label="邀请人QQ">
        <el-input v-model="form.inviterQq"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="editCodeDialog = false">取消</el-button>
        <el-button type="primary" @click="doSubmit" :loading="loading">确认</el-button>
      </span>
    </template>
  </el-dialog>
  <el-button size="large" type="primary" @click="editCodeDialog = true">修改</el-button>
</template>

<script lang="ts" setup>
import { defineProps, inject, ref, watch } from 'vue'
import { editCode } from '@/api/admin'
import { ElMessage } from 'element-plus'

const reload: any = inject('reload')
const editCodeDialog = ref<boolean>(false)
const loading = ref<boolean>(false)
const props = defineProps<{ data: any }>()
const form = ref(props.data)
watch(
  () => props.data,
  (newValue) => {
    form.value = newValue
  }
)
const doSubmit = () => {
  loading.value = true
  editCode(form.value).then(() => {
    ElMessage.success('修改成功')
    editCodeDialog.value = false
    reload()
  }).finally(() => {
    loading.value = false
  })
}
</script>

<style scoped>

</style>
